package com.framework.core.easyui.domain;

import com.framework.core.util.StringUtil;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;

public class DataGridModel  implements java.io.Serializable {
	
	private static final long serialVersionUID = 7232798260610351343L;
	private int page; //当前页,名字必须为page
	private int rows ; //每页大小,名字必须为rows
	private String sort; //排序字段
	private String order; //排序规则

	/**
	 * 封装分页的基本信息
	 *
	 * @param dgm
	 * @return
	 */
	public static PageRequest getPageRequest(DataGridModel dgm) {

		PageRequest pr = null;
		if (StringUtil.isEmpty(dgm.getSort())) {
			pr = new PageRequest(dgm.getPage() - 1, dgm.getRows());
		} else {
			Sort sort = null;
			if ("DESC".equals(dgm.getOrder().toUpperCase())) {
				sort = new Sort(Sort.Direction.DESC, dgm.getSort());
			} else {
				sort = new Sort(Sort.Direction.ASC, dgm.getSort());
			}
			pr = new PageRequest(dgm.getPage() - 1, dgm.getRows(), sort);
		}
		return pr;
	}

	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public int getRows() {
		return rows;
	}
	public void setRows(int rows) {
		this.rows = rows;
	}
	public String getSort() {
		return sort;
	}
	public void setSort(String sort) {
		this.sort = sort;
	}
	public String getOrder() {
		return order;
	}
	public void setOrder(String order) {
		this.order = order;
	}
	
	
}
